package com.daxia.ogmall.web.controller.m;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daxia.ogmall.common.MyJSONObject;
import com.daxia.ogmall.dto.AdDTO;
import com.daxia.ogmall.dto.DesignDTO;
import com.daxia.ogmall.dto.api.AdAPIDTO;
import com.daxia.ogmall.dto.api.info.AdInfoAPIDTO;
import com.daxia.ogmall.support.MPage;

@Controller
@RequestMapping(value = "/m/ad", produces = "application/json;charset=UTF-8")
public class MAdController extends MBaseController {
    
    @ResponseBody
    @RequestMapping("list")
    public String list(AdDTO dto, MPage page) throws Exception {
    
        List<AdDTO> adDTOs = adService.find(dto, page);

        return toApiOutput(adDTOs, AdAPIDTO.class, AdInfoAPIDTO.class, page);
    }
    
    @ResponseBody
    @RequestMapping("index")
    public String index(AdDTO dto, MPage page) throws Exception {
    	List<DesignDTO> designDTOs = designService.findCommunityDesign(page);
    	MyJSONObject data = new MyJSONObject();
    	if (CollectionUtils.isNotEmpty(designDTOs)) {
    		DesignDTO d = designDTOs.get(0);
    		data.put("images", d.getImageList());
    		data.put("url", d.getView3dURL());
    	}
    	super.setPageInfo(data, page);
        return toJson(data);
    }
    
}
